package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.XiaofeiMapper;
import work.xiaohong.gupiao.pojo.Xiaofei;
import work.xiaohong.gupiao.service.XiaofeiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class XiaofeiServiceImpl implements XiaofeiService {

    @Autowired
    private XiaofeiMapper xiaofeiMapper;


    /**
     * 条件+分页查询Xiaofei
     * @param xiaofei 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Xiaofei> findPage(Xiaofei xiaofei, int page, int size){
        // 构建查询条件
        QueryWrapper<Xiaofei> queryWrapper = new QueryWrapper<Xiaofei>(xiaofei);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return xiaofeiMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Xiaofei
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Xiaofei> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return xiaofeiMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Xiaofei
     * @param xiaofei
     * @return
     */
    @Override
    public List<Xiaofei> findList(Xiaofei xiaofei){
        // 构建查询条件
        QueryWrapper<Xiaofei> queryWrapper = new QueryWrapper<Xiaofei>(xiaofei);
        // 查询数据
        return xiaofeiMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Xiaofei
     * @param id
     */
    @Override
    public void delete(Integer id){
        xiaofeiMapper.deleteById(id);
    }

    /**
     * 根据ID修改Xiaofei
     * @param xiaofei
     */
    @Override
    public void update(Xiaofei xiaofei){
        xiaofeiMapper.updateById(xiaofei);
    }

    /**
     * 增加Xiaofei
     * @param xiaofei
     */
    @Override
    public void add(Xiaofei xiaofei){
        xiaofeiMapper.insert(xiaofei);
    }

    /**
     * 根据ID查询Xiaofei
     * @param id
     * @return
     */
    @Override
    public Xiaofei findById(Integer id){
        return  xiaofeiMapper.selectById(id);
    }

    /**
     * 查询全部Xiaofei数据
     * @return
     */
    @Override
    public List<Xiaofei> findAll() {
        return xiaofeiMapper.selectList(null);
    }
}
